package com.leoman.plz_p.presenter;


import com.leoman.plz_p.interfaces.AnswerActivityView;
import com.leoman.plz_p.module.api.ExamApi;
import com.leoman.plz_p.module.bean.BaseData;
import com.leoman.plz_p.module.bean.MapData;
import com.leoman.plz_p.subscriber.ResponseSubscriber;
import com.leoman.plz_p.utils.UserHelper;

import cn.com.corelib.api.ResponseTransformer;
import cn.com.corelib.base.BasePresenter;

public class AnswerActivityPresenter extends BasePresenter<AnswerActivityView> {

    private ExamApi examApi;

    @Override
    protected void onViewAttach() {
        super.onViewAttach();
        examApi=getApi(ExamApi.class);
    }

    public void deleteMistakeQuestion(String id){
        examApi.deleteMistakeQuestion(UserHelper.getToken(),id)
                .compose(new ResponseTransformer<>(this.<BaseData<MapData>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<MapData>>(view) {
                    @Override
                    public void success(BaseData<MapData> mapDataBaseData) {
                        view.obtainDeleteSuccess();
                    }
                });
    }

    public void submitExam(String examId,String source,String total,String error){
        getView().showLoading();
        examApi.submitExam(UserHelper.getToken(),examId,source,total,error)
                .compose(new ResponseTransformer<>(this.<BaseData<MapData>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<MapData>>(view) {
                    @Override
                    public void success(BaseData<MapData> mapDataBaseData) {
                        view.submitExamSuccess(mapDataBaseData.data.source,mapDataBaseData.data.errorCount);
                    }
                });
    }

    @Override
    public void onStart() {

    }
}